﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Manage.Master" AutoEventWireup="true"
    CodeBehind="freightManage.aspx.cs" Inherits="ZF.WS.Admin.shop.freightManage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script src="/js/jqPlugins/areaJson.js" type="text/javascript"></script>

    <script src="/js/jqPlugins/jquery.json-2.2.min.js" type="text/javascript"></script>

    <script>
        $(function() {

            $.formValidator.initConfig({ formid: document.forms[0].id, onerror: function(msg) { alert(msg) } });



            $(".tbName").formValidator({ tipid: "tbNameTip", onfocus: " ", oncorrect: " ", onshow: " ", onempty: "  " })
    .inputValidator({ min: 1, onerror: "请输入模板名称" });
            $(".fttab input").onlypressnum();
            $(".rstxt").onlypressnum();
        });

    </script>

    <div class="editContainer" style="min-width: 1200px; *width: 1200px">
        <table class=" w100_ edit  edit1  ">
            <tbody>
                <tr>
                    <th colspan="4">
                        <div class="c">
                        </div>
                    </th>
                </tr>
                <tr>
                    <td class="ll"  >
                        <div class="c">
                           <span class="xh_">*</span> 模板名称：
                        </div>
                    </td>
                    <td class="lr" colspan="3"  >
                        <div class="c">
                            <zf:TextBox runat="server" ID="tbName" class="ltxt"></zf:TextBox>
                            <span class="zx_" id="tbNameTip"></span>
                        </div>
                    </td>
                </tr>
                <% var areas = new string[] { "北京市", "天津市", "河北省", "山西省", "辽宁省", "吉林省", "上海市", "江苏省", "浙江省", "安徽省", "福建省", "江西省", "山东省", "河南省", "内蒙古自治区", "黑龙江省", "湖北省", "湖南省", "广东省", "广西壮族自治区", "海南省", "四川省", "重庆市", "台湾省", "贵州省", "云南省", "西藏自治区", "陕西省", "甘肃省", "青海省", "宁夏回族自治区", "新疆维吾尔族自治区", "香港特别行政区", "澳门特别行政区", "海外" }; %>
                <tr>
                    <td class="ll"  >
                        <div class="c">
                            各地区价格设置（元）：
                            
                        </div>
                    </td>
                    <td class="lr" colspan="3"  >
                        <div class="c">
                        <style>
                            .fttab th{ background:#E7F7F8; color:#000;  text-align:right;  font-size:12px; padding-right:5px;}
                            .fttab input{ width:30px;}
                        </style>
                            <table class="fttab">
                            <% for(int i=0;i<areas.Length;i++){ %>
                               <%=i % 3 == 0 ? "<tr>" : ""%>
                                
                                    <th bind="<%=i %>"><%=areas[i]%></th><td><input class="sstxt" type="text"  bind="<%=i %>" /></td>
                                
                                 <%=i % 3 == 2 ? "</tr>" : ""%>
                                <%} %>
                            </table>
                        </div>
                    </td>
                </tr>
               <tr>
                    <td class="ll"  >
                        <div class="c">
                            重置价格：
                        </div>
                    </td>
                    <td class="lr" colspan="3"  >
                        <div class="c">
                            <input type="text" class="sstxt rstxt" /><input type="button" class="linkbtn rsall" value="重置所有价格" />
                            <input type="button" class="linkbtn rsempty" value="重置未输入价格" />
                            
                        </div>
                    </td>
                </tr> <zf:TextBox runat="server" ID="tbJson" class="dn_"></zf:TextBox>
                <script>
                    $(function() {

                        $(".rsall").click(function() {
                            if ($(".rstxt").val() == "")
                                alert("请输入重置价格");
                            else {
                                $(".fttab input").val($(".rstxt").val());
                            }
                        });
                        $(".rsempty").click(function() {
                            if ($(".rstxt").val() == "")
                                alert("请输入重置价格");
                            else {
                                $(".fttab input[value='']").val($(".rstxt").val());
                            }
                        });
                        $(document.forms[0]).submit(function() {
                            var success = true; ;
                            var reg = new RegExp("^[0-9]*$");
                            var arr = [];
                            var ths = $(".fttab th");
                            var tbs = $(".fttab input");
                            tbs.each(function() {

                                if (!reg.test(this.value) || this.value == "") {
                                    alert("价格输入错误");
                                    success = false;
                                    return false;
                                }
                            });
                            for (var i = 0; i < tbs.length; i++) {
                                arr.push({ Key: $(ths[i]).html(), Text: parseInt(tbs[i].value) });
                            }
                            if (!success)
                                return false;
                            $(".tbJson").val($.toJSON(arr));
                            return true;
                        });
                        init();
                    });
                    function init() {
                        var json = null;
                        if ($(".tbJson").val() != "")
                            json = $.evalJSON($(".tbJson").val());
                      
                        if (json != null) {
                            var fttab = $(".fttab");

                            $(json).each(function() {
                                var th = fttab.find(String.format("th:contains('{0}')", this.Key));
                                var bind = th.attr("bind");
                           
                                fttab.find(String.format("input[bind={0}]", bind)).val(this.Text);


                            });
                        }
                    }
                </script>
                <%--<tr>
                    <td class="ll">
                        <div class="c">
                            模板名称：
                        </div>
                    </td>
                    <td class="lr"  colspan="3" >
                        <div class="c setItems">
                            <ul>
                            </ul>
                        </div>
                        <div class="  dn_">
                            <ul class="template">
                                <li>地区选择：<select>
                                    <option>北京市</option>
                                    <option>天津市</option>
                                    <option>河北省</option>
                                    <option>山西省</option>
                                    <option>辽宁省</option>
                                    <option>吉林省</option>
                                    <option>上海市</option>
                                    <option>江苏省</option>
                                    <option>浙江省</option>
                                    <option>安徽省</option>
                                    <option>福建省</option>
                                    <option>江西省</option>
                                    <option>山东省</option>
                                    <option>河南省</option>
                                    <option>内蒙古自治区</option>
                                    <option>黑龙江省</option>
                                    <option>湖北省</option>
                                    <option>湖南省</option>
                                    <option>广东省</option>
                                    <option>广西壮族自治区</option>
                                    <option>海南省</option>
                                    <option>四川省</option>
                                    <option>重庆市</option>
                                    <option>台湾省</option>
                                    <option>贵州省</option>
                                    <option>云南省</option>
                                    <option>西藏自治区</option>
                                    <option>陕西省</option>
                                    <option>甘肃省</option>
                                    <option>青海省</option>
                                    <option>宁夏回族自治区</option>
                                    <option>新疆维吾尔族自治区</option>
                                    <option>香港特别行政区</option>
                                    <option>澳门特别行政区</option>
                                    <option>海外</option>
                                </select>&nbsp;&nbsp;价格设置:<input type="text" value="{0}" class="sstxt" />
                                
                                
                                &nbsp;<input type="button" class="linkbtn delItem" onclick="$(this.parentNode).remove();" value=" 删 除 " />
                                </li>
                            </ul>
                        </div>
                       
                        <input type="button" class="linkbtn addItem" value=" 添 加 " />

                        <script>
                            $(function() {
                                var template = $(".template").html();
                                var ul = $(".setItems ul")
                                $(".addItem").click(function() {
                                    ul.append(String.format(template, 0));
                                });
                                $(document.forms[0]).submit(function() {
                                    var success = true; ;
                                    var reg = new RegExp("^[0-9]*$");
                                    var arr = [];
                                    ul.find("li").each(function() {
                                        var li = $(this);
                                        var txt = li.find(":text").val();
                                        var area = li.find("select")[0].value;

                                        if (!reg.test(txt)) {
                                            alert("价格输入错误");
                                            li.find(":text")[0].fouce();
                                            success = false;
                                            return;
                                        }
                                        arr.push({ area: area, price: parseInt(txt) });
                                    });
                                    if (!success)
                                        return false;
                                    $(".tbJson").val($.toJSON(arr));

                                    return true;
                                });
                                var json = null;
                                if ($(".tbJson").val() != "")
                                    json = $.evalJSON($(".tbJson").val());
                                if (json != null) {
                               
                                    $(json).each(function() {
                                        ul.append(String.format(template, this.price));
                                        alert(ul.find("select").last());
                                        ul.find("select").last()[0].value = this.area;
                                    });
                                }
                            });
                        </script>

                    </td>
                </tr>--%>
            </tbody>
            <tbody>
                <tr class="b">
                    <td colspan="4">
                        <div>
                             <zf:Button ID="btAdd" BindOper="AddNew" class="linkbtn addSubmit" runat="server"
                                OnClick="AddSubmit" Text=" 添 加 "></zf:Button>
                            <zf:Button ID="btEdit" BindOper="Edit" class="linkbtn addSubmit" runat="server" OnClick="EditSubmit"
                                Text=" 修 改 "></zf:Button>
                            <input type="button" class="linkbtn" value=" 取 消 " onclick="doPage('<%=this.ListPage %>');" />
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</asp:Content>
